package pers.qianyu.model.dto;


import cn.hutool.core.bean.*;
import io.swagger.annotations.*;
import lombok.*;
import lombok.experimental.*;
import pers.qianyu.model.entity.*;
import pers.qianyu.utils.*;

import javax.validation.constraints.*;

@Data
@Accessors(chain = true)
@ApiModel(value = "用户信息", description = "前端传入json格式的用户信息")
public class UserDTO {
    @ApiModelProperty(notes = "用户名", example = "admin")
    @NotBlank(message = "用户名不能为空")
    private String username;
    @ApiModelProperty(notes = "密码", example = "******")
    @NotBlank(message = "密码不能为空")
    private String password;

    public UserPO toUserPO() {
        return new Converter().convertToPO(this);
    }

    private static class Converter implements IConverter<UserDTO, UserPO> {
        @Override
        public UserPO convertToPO(UserDTO userDTO) {
            UserPO po = new UserPO();
            BeanUtil.copyProperties(userDTO, po);
            po.setPassword(SecurityUtil.encryptPassword(po.getPassword()));
            return po;
        }
    }
}
